#include "./list/list.h"
#include <stdlib.h>

void __list_add(struct list *_new, struct list *prev, struct list *next)
{
	next->prev = _new;
	_new->next = next;
	_new->prev = prev;
	prev->next = _new;
}

void list_add_head(struct list *_new, struct list *head)
{
	__list_add(_new, head, head->next);
}

void list_add_tail(struct list *_new, struct list *head)
{
	__list_add(_new, head->prev, head);
}

void __list_del(struct list *prev, struct list *next)
{
	next->prev = prev;
	prev->next = next;
}

void list_del(struct list *entry)
{
	__list_del(entry->prev, entry->next);

	entry->next = NULL;
	entry->prev = NULL;
}

int list_is_last(const struct list *entry, const struct list *head)
{
	return entry->next == head;
}

int list_empty(const struct list *head)
{
	return head->next == head;
}
